#include "personalcenter.h"
#include "ui_personalcenter.h"

PersonalCenter::PersonalCenter(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::PersonalCenter)
{
    ui->setupUi(this);
    ui->comboBox->addItems({"adult","student","elderly","child"});
    connect(ui->pushButton,&QPushButton::clicked,this,&PersonalCenter::OnUserDataChange);
}
// enum Role{
//     adult,
//     student,
//     elderly,
//     child
// };
PersonalCenter::PersonalCenter(User cur,QWidget* parent):QWidget(parent),ui(new Ui::PersonalCenter){
    ui->setupUi(this);
    current = cur;
    ui->comboBox->addItems({"adult","student","elderly","child"});
    ui->txt_email->setText(cur.email);
    ui->txt_tel->setText(cur.tel);
    ui->spinBox->setValue(cur.age);
    ui->comboBox->setCurrentIndex((int)cur.type);
}
void PersonalCenter::setUser(User cur){
    this->current = cur;
    setText(current);
}
void PersonalCenter::setText(User cur){
    ui->txt_email->setText(cur.email);
    ui->txt_tel->setText(cur.tel);
    ui->spinBox->setValue(cur.age);
    ui->comboBox->setCurrentIndex((int)cur.type);
}
void PersonalCenter::OnUserDataChange(){
    User user = current;
    user.email = ui->txt_email->text();
    user.age = ui->spinBox->value();
    user.tel = ui->txt_tel->text();
    user.type = (Role)ui->comboBox->currentIndex();
    emit changeUserData(current);
}
PersonalCenter::~PersonalCenter()
{
    delete ui;
}
